package patrol.mobile.com.mobilepatrol.activity.security.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.security.emergency.EmergencyPackageEdit3Activity;
import patrol.mobile.com.mobilepatrol.activity.security.emergency.EmergencyPeopleInfoActivity;
import patrol.mobile.com.mobilepatrol.bean.ProtectListBean;
import patrol.mobile.com.mobilepatrol.utils.DateUtil;

/**
 * Created by admin on 2018/9/9.
 */

public class EmergencyProtectListAdapter extends BaseQuickAdapter<ProtectListBean> {


    public EmergencyProtectListAdapter(Context context) {
        super(context);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_emergency_protectlist_list;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final ProtectListBean item) {

        holder.setText(R.id.tv_num, (holder.getAdapterPosition() + 1) + "");
        holder.setText(R.id.tv_householder, item.getHouseholder());
        String houseRented = item.getHouseRented();
        holder.setText(R.id.tv_houseRented, houseRented.equals("1") ? "是" : "否");
        if (houseRented.equals("1")) {
            holder.setBackgroundRes(R.id.tv_houseRented, R.drawable.shape_rect_red);
            holder.setTextColor(R.id.tv_houseRented,mContext.getResources().getColor( R.color.white));
        }else{
            holder.setBackgroundRes(R.id.tv_houseRented,0);
            holder.setTextColor(R.id.tv_houseRented,mContext.getResources().getColor(R.color.black_light));
        }


        String keyPersonel = item.getKeyPersonel();
        holder.setText(R.id.tv_keyPersonel, keyPersonel.equals("1") ? "是" : "否");
        if (keyPersonel.equals("1")) {
            holder.setBackgroundRes(R.id.tv_keyPersonel, R.drawable.shape_rect_red);
            holder.setTextColor(R.id.tv_keyPersonel,mContext.getResources().getColor(R.color.white));
        }else{
            holder.setBackgroundRes(R.id.tv_keyPersonel,0);
            holder.setTextColor(R.id.tv_keyPersonel,mContext.getResources().getColor(R.color.black_light));
        }


        String has = item.getIsHas();
        holder.setText(R.id.tv_isHas,has );
        if (has.equals("无异常")) {
            holder.setBackgroundRes(R.id.tv_isHas, 0);
            holder.setTextColor(R.id.tv_isHas,mContext.getResources().getColor(R.color.black_light));
        }else{
            holder.setBackgroundRes(R.id.tv_isHas,R.drawable.shape_rect_red);
            holder.setTextColor(R.id.tv_isHas,mContext.getResources().getColor(R.color.white));
        }

        if (TextUtils.isEmpty(item.getReportDate())) {

        } else {
            holder.setText(R.id.tv_reportDate, DateUtil.long2string(DateUtil.format1, Long.parseLong(item.getReportDate())));
        }

        holder.setText(R.id.tv_auditName, item.getAuditName());

        holder.setOnClickListener(R.id.rl_root, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, EmergencyPeopleInfoActivity.class);
                intent.putExtra("id", item.getId());
                intent.putExtra("holderId", item.getHolderId());
                mContext.startActivity(intent);
            }
        });

    }
}
